/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uit.ejb.bo.phieuthuedv;

import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.sql.rowset.WebRowSet;
import uit.ejb.dae.phieuthuedv.PhieuThueDVDAERemote;
import uit.ejb.dae.phieuthuedv.PhieuThueDVDAERemoteHome;
import uit.ejb.dto.PhieuThueDVDTO;

/**
 *
 * @author Restart
 */
public class PhieuThueDVBO implements SessionBean {
    
    private SessionContext context;
    
    // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">;

    // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
    // TODO Add business methods or web service operations

    /**
     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
     */
    public void setSessionContext(SessionContext aContext) {
        context = aContext;
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() {
        
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() {
        
    }
    
    /**
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() {
        
    }
    
    // </editor-fold>;

    /**
     * See section 7.10.3 of the EJB 2.0 specification
     * See section 7.11.3 of the EJB 2.1 specification
     */
    public void ejbCreate() {
        // TODO implement ejbCreate if necessary, acquire resources
        // This method has access to the JNDI context so resource aquisition
        // spanning all methods can be performed here such as home interfaces
        // and data sources.
    }

    private PhieuThueDVDAERemote getPhieuThueDVObject() throws RemoteException, ClassCastException, FinderException, NamingException {
        InitialContext ctx = new InitialContext();
        Object obj = ctx.lookup("ejb/PhieuThueDVDAE");
        PhieuThueDVDAERemoteHome phome = (PhieuThueDVDAERemoteHome) PortableRemoteObject.narrow(obj, PhieuThueDVDAERemoteHome.class);
        PhieuThueDVDAERemote ptdv = phome.findByPrimaryKey("");
        return ptdv;
    }

    public boolean phieuThueDV_Insert(PhieuThueDVDTO phieuthuedv) {
        try{
            PhieuThueDVDAERemote ptdv = getPhieuThueDVObject();
            return ptdv.phieuThueDV_Insert(phieuthuedv);
        }catch(Exception e){
            return false;
        }
    }

    public boolean phieuThueDV_Delete(String id) {
        try{
            PhieuThueDVDAERemote ptdv = getPhieuThueDVObject();
            return ptdv.phieuThueDV_Delete(id);
        }catch(Exception e){
            return false;
        }
    }

    public WebRowSet phieuThueDV_GetById(String id) {
        try{
            PhieuThueDVDAERemote ptdv = getPhieuThueDVObject();
            return ptdv.phieuThueDV_GetById(id);
        }catch(Exception e){
            return null;
        }
    }

    public WebRowSet phieuThueDV_GetByTop(String top, String where, String order) {
        try{
            PhieuThueDVDAERemote ptdv = getPhieuThueDVObject();
            return ptdv.phieuThueDV_GetByTop(top, where, order);
        }catch(Exception e){
            return null;
        }
    }
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
    
}
